<?php
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
function fetch_all($sql) {

	$data = array();
	$query = DB::query($sql);
	while ($row = DB::fetch($query)) {
			$data[] = $row;
	}
	DB::free_result($query);
	return $data;
}
//forum_threadimage
function forum_threadimage_fetch_all_by_tid($condition,$num) {
		return fetch_all("SELECT * FROM ".DB::table('forum_threadimage')." WHERE 1 $condition ORDER BY tid DESC LIMIT 0, $num");
}

//forum_thread
function forum_thread_fetch_by_tid($tid) {
	return DB::fetch_first("SELECT * FROM ".DB::table('forum_thread')." WHERE tid=$tid");
}
function forum_thread_fetch_all_by_tid($condition) {
	//echo $condition;
	return fetch_all("SELECT * FROM ".DB::table('forum_thread')." WHERE displayorder IN(0,1,2,3) $condition");
}

//forum_forum
function forum_forum_fetch_by_fid($fid) {
		return DB::result_first("SELECT name FROM ".DB::table('forum_forum')." WHERE fid=$fid");
}


//forum_post
function forum_post_result_first_message_by_tid($tid) {
		return DB::fetch_first("SELECT message,authorid FROM ".DB::table('forum_post')." WHERE tid<>pid AND tid=$tid ORDER BY pid DESC");
}
function forum_post_count_all_by_dateline($dateline,$posts_num,$num){
		if($posts_num != 1314){
			$where = "where dateline >=$dateline";
		}
		
		return fetch_all("select count(pid) as num, authorid, author from ".DB::table('forum_post')." $where group by authorid order by num desc limit 0, $num");
}

//common_member
function common_member_fetch_all_by_uid($uid) {
	return DB::fetch_first("SELECT * FROM ".DB::table('common_member')." WHERE uid=$uid ORDER BY uid");
}
// 2012080813Nw3eE1OI1i
function common_member_fetch_all_newmember_by_uid($num){
	return fetch_all("SELECT uid,username,regdate FROM ".DB::table('common_member')." ORDER BY regdate DESC limit 0, $num");
}

//common_member_count
function common_member_count_fetch_all_oltime_by_uid($num){
	return fetch_all("SELECT * FROM ".DB::table('common_member_count')." ORDER BY oltime DESC limit 0, $num");
}


?>
